package project.bank.views;

import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JTable;

import project.bank.contoller.ControllerEntry;
import project.bank.framwork.BaseForm;


public class BtnWithdraw extends JButton implements ICommandBtn {
	public BaseForm context;
	public ControllerEntry contoller;

	public BtnWithdraw(BankFrm context, ActionListener listener) {
		addActionListener(listener);
		this.context = context;

		contoller = new ControllerEntry(context);
		JDialog_Entry dlg = new JDialog_Entry(context, contoller);
		dlg.setBounds(450, 20, 300, 330);
		dlg.setTitle("Withdraw");
		contoller.setDialog(dlg);
	}

	@Override
	public void execute() {
		// get selected account
		JTable table = context.getTable();
		int selection = table.getSelectionModel().getMaxSelectionIndex();
		if (selection >=0){
	            String accnr = (String)table.getModel().getValueAt(selection,0);
	            contoller.setAccount(accnr);
	    }
		contoller.showDialog();
	}

}
